home *** CD-ROM | disk | FTP | other *** search
- Path: gulfa.kuwait.net!shadows
- From: shadows@whateva.kuwait.net (The ShadowS Know)
- Newsgroups: comp.lang.c
- Subject: Re: How to access memory allocated in function
- Date: 21 Apr 1996 11:32:30 GMT
- Organization: Gulfnet Kuwait
- Message-ID: <slrn4nkrsq.bv6.shadows@whateva.kuwait.net>
- References: <4ddbe3$so3@josie.abo.fi>
- NNTP-Posting-Host: whateva.kuwait.net
- NNTP-Posting-User: shadows
- X-Newsreader: slrn (0.8.7.1 UNIX)
-
- In article <4ddbe3$so3@josie.abo.fi>, Christoffer Sundqvist wrote:
- >Hello
- >
- >
- >How can i access memory allocated dynamically in a function after i leave the
- >function, something like this:
- >
- >main()
- >{
- >int *p;
- >sub(p);
- >}
- >
- >void sub(int *p)
- >{
- > p = malloc(.....);
- >}
- >
- >Thanks !
- Im sorry ive mailed the person and followed it up here.. *sigh* ok here it goes
- again..
-
- p = (int *)malloc(sizeof(int));
- What we've done is cast it as an pointer to an integer then allocated it
- the size of one int (thus it points to a space in memory that has the size
- of holding 1 integer). Ofcourse anything might be in that memory address
- you'd need to place something there to clear it up.
- --
- Thamer Al-Herbish
- (ShadowS)
- "Teenage angst paid off well.. now I'm bored and old."- Kurt Cobain.
- -------------------------------------------------------------------------------
-
-